home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Auxiliary.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-26  |  7.3 KB  |  293 lines

  1. /* 
  2.  *  Auxiliary.cpp
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. #include <windows.h>
  25. #include <commctrl.h>
  26. #include "auxiliary.h"
  27. #include "resource.h"
  28. #include "stdio.h"
  29. #include <math.h>
  30.  
  31.  
  32.  
  33. int GetOutputFileName(HWND hWnd, char* fileName,char* Dir, char* Title){
  34.     OPENFILENAME oifn;
  35.         // Initialize OPENFILENAME
  36.         ZeroMemory(&oifn, sizeof(OPENFILENAME));
  37.         oifn.lStructSize = sizeof(OPENFILENAME);
  38.         oifn.hwndOwner = hWnd;
  39.         oifn.lpstrFile = fileName;
  40.         oifn.nMaxFile = 1024;
  41.         oifn.lpstrFilter = "";
  42.         oifn.nFilterIndex = 1;
  43.         oifn.lpstrFileTitle = NULL;
  44.         oifn.lpstrTitle = Title;
  45.         oifn.nMaxFileTitle = 0;
  46.         oifn.lpstrInitialDir = Dir;
  47.         oifn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  48.         if(!GetSaveFileName(&oifn))
  49.             return 0;
  50.         return 1;
  51. }
  52.  
  53. HWND CreateNormalWindow(WNDPROC WndProc, HINSTANCE hInstance, HWND hParent){
  54.         
  55.    return CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DISPLAY), hParent, (DLGPROC)WndProc);
  56.     
  57.  
  58. }
  59.  
  60. void WindowShow(HWND hWnd){
  61.     ShowWindow(hWnd, SW_SHOW);
  62. }
  63. void WindowHide(HWND hWnd){
  64.     ShowWindow(hWnd, SW_HIDE);
  65. }
  66.  
  67. void WindowResize(HWND window, int w, int h){
  68.     RECT rc;
  69.     GetWindowRect(window, &rc);
  70.     MoveWindow(window, rc.left, rc.top, w, h , TRUE);
  71. }
  72.  
  73. void WindowClientResize(HWND window, int w, int h){
  74.     RECT rc;
  75.             SetRect(&rc, 0, 0, w, h);
  76.             AdjustWindowRect(&rc,GetWindowLong(window,GWL_STYLE),FALSE);
  77.             WindowResize(window, rc.right-rc.left, rc.bottom - rc.top);
  78.     
  79. }
  80.  
  81. void WindowMove(HWND window, int x, int y){
  82.     RECT rc;
  83.     GetWindowRect(window, &rc);
  84.     MoveWindow(window, x, y, rc.right-rc.left, rc.bottom-rc.top, TRUE);
  85. }
  86. void SetText(HWND hWnd, char *text){
  87.     if(text==NULL)
  88.         return;
  89.     SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)text);
  90. }
  91. void MenuSetText(HMENU hMenu,int item ,char *text ){
  92.     MENUITEMINFO item_info;
  93.     int kk;
  94.     if(text==NULL)
  95.         return;
  96.  
  97.     item_info.cbSize = sizeof(item_info);
  98. //    item_info.fMask  = MIIM_DATA|MIIM_ID|MIIM_STATE|MIIM_SUBMENU|MIIM_TYPE; 
  99. //    GetMenuItemInfo( hMenu, item, TRUE, &item_info);
  100.  
  101.     item_info.fMask  = MIIM_TYPE; 
  102.     item_info.fType         = MFT_STRING;
  103.     item_info.dwTypeData    = text;
  104.     SetMenuItemInfo( hMenu, item, TRUE, &item_info);
  105.  
  106. }
  107.  
  108. void MenuAddItem(HMENU hMenu,int item , int wID,char *text){
  109.     MENUITEMINFO item_info;
  110.     int kk;
  111.     if(text==NULL)
  112.         return;
  113.  
  114.     item_info.cbSize = sizeof(item_info);
  115.  
  116.     item_info.fMask  = MIIM_TYPE|MIIM_ID; 
  117.     item_info.fType         = MFT_STRING;
  118.     item_info.dwTypeData    = text;
  119.     item_info.wID           = wID;
  120.     InsertMenuItem( hMenu, item, TRUE, &item_info);
  121. }
  122. HMENU MenuGetPopup( HMENU hMenu, int item ){
  123.     MENUITEMINFO item_info;
  124.     int kk;
  125.     item_info.cbSize = sizeof(item_info);
  126.     item_info.fMask  = MIIM_SUBMENU; 
  127.     GetMenuItemInfo( hMenu, item, TRUE, &item_info);
  128.     return item_info.hSubMenu;
  129.  
  130. }
  131. void MenuCheck(HWND hWnd, int item)
  132. {
  133.     CheckMenuItem(GetMenu(hWnd),item, MF_CHECKED);
  134. }
  135. void MenuUnCheck(HWND hWnd, int item)
  136. {
  137.     CheckMenuItem(GetMenu(hWnd),item, MF_UNCHECKED);
  138.  
  139. }
  140. void MenuEnable(HWND hWnd, int item)
  141. {
  142.     EnableMenuItem(GetMenu(hWnd), item, MF_ENABLED);
  143. }
  144. void MenuDisable(HWND hWnd, int item)
  145. {
  146.     EnableMenuItem(GetMenu(hWnd), item, MF_GRAYED);
  147. }
  148. void MenuSetText(HWND hWnd, int item){
  149.  
  150. }
  151. void TabSetText(HWND hTab, int item, char *text){
  152.     TCITEM props;
  153.  
  154.     if(text==NULL)
  155.         return;
  156.     
  157.     props.mask    = TCIF_TEXT;
  158.     props.pszText = text;
  159.     SendMessage( hTab, TCM_SETITEM, (WPARAM) item, (LPARAM)&props);
  160.  
  161. }
  162. void DlgSetFocus(HWND hDlg, int control){
  163.     SetFocus(GetDlgItem(hDlg, control));
  164. }
  165.  
  166. void DlgCheck(HWND hDlg, int item){
  167.  
  168.     SendDlgItemMessage( hDlg, item, BM_SETCHECK, BST_CHECKED ,0);
  169. }
  170.  
  171. void DlgUnCheck(HWND hDlg, int item){
  172.     SendDlgItemMessage( hDlg, item, BM_SETCHECK, BST_UNCHECKED ,0);
  173. }
  174.  
  175. bool DlgIsChecked(HWND hDlg, int item){
  176.     return (SendDlgItemMessage( hDlg, item, BM_GETCHECK, 0, 0)==BST_CHECKED);
  177. }
  178.  
  179. void DlgEnable(HWND hDlg, int item){
  180.      EnableWindow( GetDlgItem(hDlg, item), true); 
  181. }
  182. void DlgDisable(HWND hDlg, int item){
  183.          EnableWindow( GetDlgItem(hDlg, item), false); 
  184. }
  185.  
  186. char *DlgGetText( HWND hDlg, int item, char* text){
  187.     if(text==NULL)
  188.         return NULL;
  189.  
  190.     GetDlgItemText( hDlg, item, text, 1024);
  191.     return text;
  192. }
  193. int DlgGetText( HWND hDlg, int item){
  194.     char szTemp[1024];
  195.     GetDlgItemText( hDlg, item, szTemp, 1024);
  196.     return atoi(szTemp);
  197. }
  198. void DlgSetText(HWND hDlg, int item, int number){
  199.  
  200.     char szTemp[1024];
  201.     SetDlgItemText(hDlg, item, itoa(number, szTemp, 10));
  202. }
  203. void DlgSetDouble(HWND hDlg, int item, double number){
  204.     char szTemp[1024];
  205.     sprintf(szTemp, "%.2f", number);
  206.     SetDlgItemText(hDlg, item, szTemp);
  207. }
  208.  
  209. void DlgSetText(HWND hDlg, int item, char* text){
  210.     if(text==NULL)
  211.         return;
  212.  
  213.     SetDlgItemText(hDlg, item, text);
  214. }
  215.  
  216. int DlgGetInt(HWND hDlg, int item){
  217.     char szTemp[1024];
  218.     GetDlgItemText( hDlg, item, szTemp, 1024);    
  219.     return atoi(szTemp);
  220. }
  221.  
  222. void DlgCheckBoxState(HWND hDlg, int item, int state)
  223. {
  224.     if(state)
  225.         DlgCheck(hDlg, item);
  226.     else
  227.         DlgUnCheck(hDlg, item);
  228. }
  229. // LIST BOXES
  230. void ListAddText(HWND list, char *text){
  231.     SendMessage(list, CB_ADDSTRING, 0, (LPARAM) text);
  232. }
  233. int ListGetCur(HWND list){
  234.     return  SendMessage(list, CB_GETCURSEL, 0,0);
  235. }
  236. void ListSetCur(HWND list, int cur){
  237.     SendMessage(list, CB_SETCURSEL, cur, 0);
  238. }
  239. void MillisecondsToTime( char *str, DWORD time)
  240. {
  241.  
  242.     //Me pasan el tiempo que tengo que formatear en milisegundos
  243.     int segundos, minutos, horas;
  244.     if(str==NULL) return;
  245.     segundos= floor(time/1000);
  246.     segundos=segundos%60;
  247.     minutos= floor(time/60000);
  248.     minutos= minutos%60;
  249.     horas=   floor((double)time/3600000);
  250.     if (minutos <=9)
  251.         if (segundos<=9)
  252.             sprintf( str, "%d:0%d:0%d", horas, minutos, segundos);
  253.         else
  254.             sprintf( str, "%d:0%d:%d", horas, minutos, segundos);
  255.     else
  256.         if (segundos<=9)
  257.             sprintf( str, "%d:%d:0%d", horas, minutos, segundos);
  258.         else
  259.             sprintf( str, "%d:%d:%d", horas, minutos, segundos);
  260.  
  261.     return;
  262. }
  263.  
  264. StringFrameRate(int fr, char *sFrameRate)
  265. {
  266.     int frameRate;
  267.                 switch( fr )
  268.         {
  269.             case 23976://24000/1001
  270.                 strcpy(sFrameRate, "FILM at 23.976 fps");
  271.                 break;
  272.             case 24:
  273.                 frameRate=24;
  274.                 strcpy(sFrameRate, "FILM at 24 fps");
  275.                 break;
  276.             case 25:
  277.                 frameRate=25;
  278.                 strcpy(sFrameRate, "PAL at 25 fps");
  279.                 break;
  280.             case 2997:
  281.                 frameRate=(double)30000/(double)1001;
  282.                 strcpy(sFrameRate, "NTSC at 29.97 fps");
  283.                 break;
  284.             case 30:
  285.                 frameRate=30;
  286.                 strcpy(sFrameRate, "NTSC at 30 fps");
  287.                 break;
  288.             default:
  289.                 strcpy(sFrameRate, "unknown");
  290.                 frameRate=25;
  291.         }
  292. }
  293.